package pkg4funlex;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author 4FunTeam
 */
public class Main {

    public static void main(String[] args) {
        BufferedReader inFile = null;
        Token token;
        String sourceFilePath = args[0];
        System.out.println(System.getProperty("user.dir") + " " + sourceFilePath);
        try {
            Reserved.init("reservadas.txt");
        } catch (Exception ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }

        try {
            inFile = new BufferedReader(new FileReader(args[0]));
            Scanner.init(inFile);
            Analyzer.init();
            while(true) {
                token = Analyzer.getNextToken();
                System.out.println( String.valueOf(token.getLinenum()) 
                        + " < " + token.getType()
                        + " ; " + token.getSpelling() + " >");
            }

            // TODO code application logic here
        } catch (FileNotFoundException ex) {
            System.out.println("NAO CONSEGUIU ABRIR FILE! " + ex);
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                inFile.close();
            } catch (IOException ex) {
               Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

    }
}
